pull: Handle remote web server not honoring range requests
authorColin Walters <walters@verbum.org>
Sat, 4 Apr 2015 14:49:28 +0000 (10:49 -0400)
committerColin Walters <walters@verbum.org>
Mon, 6 Apr 2015 18:33:16 +0000 (14:33 -0400)
commit115e05746beac7b52f8515e34b339d65e105b5e0
treeaee1a91a6e51d101f0cd03813107bf7525bab7a7
parent1e501422e2e5586022c19531b4856da66a479548
pull: Handle remote web server not honoring range requests

It's valid for the remote server to say 200 OK and give us the entire
file instead of a 206 Partial Content, and in that case we should blow
away the previous cached data, rather than blindly appending to it and
thus creating multiple copies of the data inside the file.

This problem primarily occurs when we do have the complete file, and
we're interrupted, then try again, where the new process didn't record
the download was already complete.  We do a range request for bytes
past the end, and some web servers (e.g. Akamai) will return 200 OK
with the whole content again, rather than a 416 Requested Range Not
Satisfiable.

Thus we could also fix this by saner caching strategy - since we know
the file is complete, rename it again to $checksum.done or something
before it's processed.  (Or really, rework how we do caching more
intelligently in general).

This fixes the issue that interrupted pulls failed with such
webservers, although repeated attempts would eventually succeed
because we'd unlink files that failed to pull.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1207292
src/libostree/ostree-fetcher.c